<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../../css/aui.css">
    <link rel="stylesheet" type="text/css" href="../../css/aui-slide.css">
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
    <link rel="stylesheet" type="text/css" href="../../css/common.css">
    <script type="text/javascript" src="../../script/api.js"></script>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #f7911b;height: 3rem;">
        <span class="aui-iconfont aui-icon-left aui-pull-left" onclick="api.closeWin();"></span>
        <div class="aui-title">提现中心</div>
    </header>
    
    <div style="width: 100%;height: 3.5rem;background-color: #fff;">
    <span style="float:left;margin-left:0.5rem;margin-top: 1.3rem;font-size:0.8rem;">
        金额:&nbsp;&nbsp;
        <div id="count">
            <input type="number" style="border: solid 0.05rem #d2d2d2;height: 1.8rem;width: 5.5rem;position: relative;left: 2rem;top:-1.6rem;font-size: 0.7rem;" placeholder=" 可提现0元" />
        </div>
        
        <button style="border-radius:0.1rem;background-color: #fbc88d;border:none;width: 3.2rem;position: relative;;height: 1.8rem;text-align:left;left: 7.45rem;top:-3.42rem;color: #000;"><span style="float:left;margin-left: -0.4rem;">全部提现</span></button>
    </span>
    <span style="float: right;font-size: 0.7rem;margin-top: 1.35rem;margin-right: 0.2rem;opacity: 0.6;">
        提现金额需大于10元
    </span>
    </div>

    <div style="width: 100%;height:3.5rem;background-color: #fff;margin-top: 0.5rem;">
        <div >
            <div  style="float: left;margin-left:-4.5rem;margin-top: 1.2rem;">提现支付宝账号：</div>
            <div><span id="payNum" style="margin-top: 1.2rem;float: right;margin-right: 3rem"></span></div>
            <span class="aui-iconfont aui-icon-right" style="margin:-1rem  1rem;float: right;" onclick="openmyass()"></span>
        </div>
    </div>

    <div style="width: 100%;height:3.5rem;background-color: #fff;margin-top: 0.5rem;">
            <div class="content" style="margin-left: 1.5rem;">
                    <div class="content-left" style="margin-top:0.5rem;">提领密码&nbsp;：</div>
                    <div class="content-right" style="margin-top: 0.8rem;margin-right: 1rem;float: right;"><input type="number" placeholder="请输入提领密码" id="pasValue"></div>
                </div>
    </div>
    <!-- <div class="aui-content aui-margin-b-15" style="float: left;">
        <div style="text-align:center;"><span class="aui-font-size-18">提领集分宝</span></div>
        <div style="text-align:center;"><span style="color:#999;">（1000集分宝=10元）</span></div>
        <br>
        <div><span>账户可提领金额:</span>&nbsp;<span class="aui-text-danger" id="count">0</span>集分宝</div>

        <div class="content">
            <div class="content-left">申请集分宝：</div>
            <div class="content-right"><input type="number" placeholder="集分宝（须为1000的整倍数）" id="leadAmount"></div>
        </div>
        <div class="content">
            <div class="content-left">提领密码&nbsp;：</div>
            <div class="content-right"><input type="number" placeholder="请输入提领密码" id="pasValue"></div>
        </div>
        <div class="content">
            <div class="content-left">支付宝账号：</div>
            <div><span id="payNum" style="line-height:50px;"></span></div>
        </div>
        <div class="content">
            <div class="content-left">真实的姓名：</div>
            <div><span id="username" style="line-height:50px;"></span></div>
        </div>
    </div> -->

    <p>
        <div style="background-color: #b5b5b5; border-radius: 0.5rem;width: 8rem;height: 2.5rem;margin-left: 32%;text-align: center;color: #fff;line-height: 2.3rem;margin-top: 1rem;" onclick="apply();">确认提领</div>
    </p>
</body>
<script type="text/javascript">

    apiready = function() {
         
        var leadAmount = $api.byId('leadAmount');
        var pasValue = $api.byId('pasValue');
        var payNum = $api.byId('payNum');
        var username = $api.byId('username');
        var count = $api.byId('count');
        var token = {
            token: $api.getStorage('token')
        };
        api.ajax({
            url: 'http://www.mk517.com/webApi/comeApply.php',
            method: 'post',
            "headers": {
                "Content-Type": "application/json"
            },
            dataType: 'json',
            data: {
                body: token
            }
        }, function(ret, err) {
            if (ret) {
                status = ret.tbtxstatus;
                if (ret.code == 1) {
                    payNum.innerHTML = ret.alipay;
                    // username.innerHTML = ret.realname;
                    if(ret.canlaim >= 100){
                    count.innerHTML = ' <input type="number" id ="count"style="border: solid 0.05rem #d2d2d2;height: 1.8rem;width: 5.5rem;position: relative;left: 2rem;top:-1.6rem;font-size: 0.7rem;" placeholder="可提现'+  ret.canlaim/100+'元" />';

                    }else{
                        count.innerHTML = ' <input type="number" id ="count"style="border: solid 0.05rem #d2d2d2;height: 1.8rem;width: 5.5rem;position: relative;left: 2rem;top:-1.6rem;font-size: 0.7rem;" placeholder="可提现0元" />';

                    }
                    // if(ret.canlaim >= 1000){count.innerHTML = ret.canlaim;}
                    
                } else if (ret.code == -2) {
                    api.alert({
                        title: '提醒',
                        msg: '您还没有登录！请先登录。。。',
                        buttons:['去登陆']
                    }, function(ret, err) {
                        if(ret.buttonIndex==1){
                            location.href = '../login.html';
                            return false;
                        }
                    });
                } else if (ret.code == -1) {
                    api.alert({
                        title: '提醒',
                        msg: '您还没有绑定支付宝，请到:设置-->安全中心-->绑定支付宝',
                        buttons:['去绑定支付宝']
                    }, function(ret, err) {
                        if(ret.buttonIndex==1){
                            location.href = './zhifubao.html';
                            return false;
                        }
                    });
                }
                // alert( JSON.stringify( ret ) );
            } else {
                alert('服务器错误！')
            }
        });


       


        window.openmyass = function() {
               
            api.openWin({
            name: 'messenger',
            url: '../mine/zhifubao.html',
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: 'auto'
            },
            pageParam: {
                token: $api.getStorage('token')
            },
            allowEdit: true
        });
               
            }

        window.apply = function() {
            var token = '';
            var body = {
                token: $api.getStorage('token'),
                leadAmount: leadAmount.value,
                pasValue: pasValue.value
            };
            if (status == 0) {
                if (pasValue.value != '' && leadAmount.value != '') {
                    api.ajax({
                        url: 'http://www.mk517.com/webApi/apply.php',
                        method: 'post',
                        dataType: 'json',
                        "headers": {
                            "Content-Type": "application/json"
                        },
                        data: {
                            body: body
                        }
                    }, function(ret, err) {
                        if (ret) {
                            if (ret.result == "true") {
                                api.alert({
                                    msg: '申请成功，已提交后台审核',
                                }, function(ret, err) {
                                    if (ret) {
                                        if (ret.buttonIndex == 1) {
                                            api.closeFrame();
                                        }

                                    } else {
                                        alert(JSON.stringify(err));
                                    }
                                });

                            } else if (ret.result == '提领密码不正确') {
                                api.alert({
                                    msg: '提领密码错误',
                                }, function(ret, err) {

                                });

                            } else if (ret.result == '提领集分宝应大于1000') {
                                api.alert({
                                    title: '提醒',
                                    msg: '提领集分宝应大于1000',
                                }, function(ret, err) {});
                            } else {
                                api.alert({
                                    msg: '申请失败，请重试！',
                                }, function(ret, err) {

                                });
                            }
                            // alert(JSON.stringify(ret));

                        } else {
                            // alert(JSON.stringify(err));
                        }
                    });

                }
            } else {
                api.alert({
                    title: '提醒',
                    msg: '您的申请正在处理中。。。。。。',
                }, function(ret, err) {

                });

            }



        };
        api.addEventListener({
    name: 'myEvent'
}, function(ret, err) {
    window.location.reload();
    
});

    }
</script>

</html>
